package com.data.center.controller;

import com.data.center.dto.AdditionalInformationDto;
import com.data.center.dto.StaffDto;
import com.data.center.util.ExcelToListUtils;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
@Slf4j
public class StaffControllerTestAC {

    @Autowired
    StaffController staffController;

    // 常量尽可能用static final修饰，防止被修改
    // 这里改成相对路径的方式，就不用每次都要拉下来改了
    private static final String filePath1 = ".\\source\\Staff\\Staff测试用例.xlsx";
    private static final String filePath2 = ".\\source\\Staff\\Staff测试用例1.xlsx";
    private static final String filePath3 = ".\\source\\Staff\\Staff测试用例2.xlsx";
    private static final String filePath4 = ".\\source\\Staff\\Staff测试用例随机抽取.xlsx";
    private static final String additionalInformationPath = ".\\source\\Staff\\增量信息.xlsx";

    @Test
    //执行时可能需修改StaffDto.java
    public void testFindStaff() {

        ExcelToListUtils<StaffDto> excelToListUtils = new ExcelToListUtils<>();
        List<StaffDto> staffDtos = excelToListUtils.excelToList(filePath4, StaffDto.class);
        log.info("staffDtos" + staffDtos);
        //  F:\作业\毕业设计\stafftest\data-center\source\Staff\Staff测试用例随机抽取.xlsx

        for (int i = 0; i <= 99; i++) {
            log.info("findStaff(staffDtos.get(" + i + "))" + staffController.findStaff(staffDtos.get(i)));
            Assert.assertEquals(staffController.findStaff(staffDtos.get(i)).getCode(), "200");

            List<StaffDto> result = (List) staffController.findStaff(staffDtos.get(i)).getResult();
            Assert.assertEquals(result.size(), 0);
        }

        // 一个完整的测试用例，包括：
        // 1. 准备数据（我们使用EXCEL+转换工具）
        // 2. 调用待测试方法（整理数据并测试）
        // 3. 验证结果，尽可能使用断言，这样如果结果和预计不同，会直接报测试失败的错误
        // 4. 数据恢复，如果测试过程中有新增、修改的数据，需要删除或回退，保障下一次测试能够成功运行（）

        // 这里要对查询到结果进行断言，判断是否正确，具体怎么断言，看业务需求
    }

    @Test
    //执行时可能需修改StaffDto.java
    public void testAddStaff() {
        ExcelToListUtils<StaffDto> excelToListUtils = new ExcelToListUtils<>();
        List<StaffDto> staffDtos = excelToListUtils.excelToList(filePath1, StaffDto.class);
        log.info("staffDtos" + staffDtos);
        //  F:\作业\毕业设计\stafftest\data-center\source\Staff\Staff测试用例.xlsx
        for (int i = 0; i <= 99; i++) {
            log.info("addStaff(staffDtos.get(" + i + "))" + staffController.addStaff(staffDtos.get(i)));
        }
    }

    @Test
    //执行时可能需修改StaffDto.java
    public void testForceAddStaff() {
        ExcelToListUtils<StaffDto> excelToListUtils = new ExcelToListUtils<>();
        List<StaffDto> staffDtos = excelToListUtils.excelToList(filePath1, StaffDto.class);
        log.info("staffDtos" + staffDtos);
        //  F:\作业\毕业设计\stafftest\data-center\source\Staff\Staff测试用例.xlsx
        for (int i = 0; i <= 99; i++) {
            log.info("forceAddStaff(staffDtos.get(" + i + "))" + staffController.forceAddStaff(staffDtos.get(i)));
        }
    }

    @Test
    //执行时可能需修改StaffDto.java
    public void testUpdateStaff() {
        ExcelToListUtils<StaffDto> excelToListUtils = new ExcelToListUtils<>();
        List<StaffDto> staffDtos = excelToListUtils.excelToList(filePath4, StaffDto.class);
        log.info("staffDtos" + staffDtos);

        for (int i = 0; i <= 99; i++) {
            log.info("updateStaff(staffDtos.get( + i + ))" + staffController.updateStaff(staffDtos.get(i)));
        }
    }

    @Test
    //执行时可能需修改StaffDto.java
    public void testLogicalDelete() {
        ExcelToListUtils<StaffDto> excelToListUtils = new ExcelToListUtils<>();
        List<StaffDto> staffDtos = excelToListUtils.excelToList(filePath4, StaffDto.class);
        log.info("staffDtos" + staffDtos);

        for (int i = 0; i <= 99; i++) {
            log.info("logicalDelete(staffDtos.get( + i + ))" + staffController.logicalDelete(staffDtos.get(i)));
            Assert.assertEquals(staffController.logicalDelete(staffDtos.get(i)).getCode(), "-1");
        }
    }

    @Test
    //执行时可能需修改StaffDto.java
    public void testPhysicalDelete() {
        ExcelToListUtils<StaffDto> excelToListUtils = new ExcelToListUtils<>();
        List<StaffDto> staffDtos = excelToListUtils.excelToList(filePath4, StaffDto.class);
        log.info("staffDtos" + staffDtos);

        for (int i = 0; i <= 99; i++) {
            log.info("physicalDelete(staffDtos.get( + i + ))" + staffController.physicalDelete(staffDtos.get(i)));
            Assert.assertEquals(staffController.physicalDelete(staffDtos.get(i)).getCode(), "-1");
        }
    }

    @Test
    //执行时可能需修改StaffDto.java
    public void testMerge() {
        ExcelToListUtils<StaffDto> excelToListUtils1 = new ExcelToListUtils<>();
        List<StaffDto> staffDtos1 = excelToListUtils1.excelToList(filePath2, StaffDto.class);
        log.info("staffDtos1" + staffDtos1);
        //  F:\作业\毕业设计\stafftest\data-center\source\Staff\Staff测试用例1.xlsx
        ExcelToListUtils<StaffDto> excelToListUtils2 = new ExcelToListUtils<>();
        List<StaffDto> staffDtos2 = excelToListUtils2.excelToList(filePath3, StaffDto.class);
        log.info("staffDtos2" + staffDtos2);
        //  F:\作业\毕业设计\stafftest\data-center\source\Staff\Staff测试用例2.xlsx

        for (int i = 0; i <= 99; i++) {
            log.info("merge(staffDtos1.get(i),staffDtos2.get(i))" + staffController.merge(staffDtos1.get(i),staffDtos2.get(i)));
            Assert.assertEquals(staffController.merge(staffDtos1.get(i),staffDtos2.get(i)).getCode(), "-1");
        }
    }
}

